<template>
  <div class="app-container" >
    <el-form label-width="120px">
      <el-form-item label="课程大于的价格">
        <el-input v-model="CourseListInfo.price"/>
      </el-form-item>
      <el-form-item label="课程是否发布">
        <el-select v-model="CourseListInfo.status" clearable placeholder="课程状态">
          <el-option value="Normal" label="已发布"/>
          <el-option value="Draft" label="未发布"/>
        </el-select>
      </el-form-item>
      <el-form-item label="更新时间">
        <el-date-picker
          v-model="CourseListInfo.gmtModified"
          type="datetime"
          placeholder="选择更新时间"
          value-format="yyyy-MM-dd HH:mm:ss"
          default-time="00:00:00"
        />
      </el-form-item>

      <el-button type="primary" icon="el-icon-search" @click="getCoursedata()">查询</el-button>
      <el-button type="default" @click="resetData()">清空</el-button>
    </el-form>




    <h3 align="center">课程列表</h3>
    <!-- 表格 -->
    <el-table
      :data="list"
      border
      fit
      highlight-current-row
    >

      <el-table-column
        label="序号"
        width="150"
        align="center">
        <template slot-scope="scope">
          {{ (current - 1) * size + scope.$index + 1 }}
        </template>
      </el-table-column>

      <el-table-column prop="title" label="名称" width="250" />

      <el-table-column label="是否发布" width="100">
        <template slot-scope="scope">
          {{ scope.row.status === 'Normal'?'已发布':'未发布' }}
        </template>
      </el-table-column>

      <el-table-column prop="lessonNum" label="总课时" width="150"/>

      <el-table-column prop="price" label="价格" width="150" />

      <el-table-column prop="teacherId" label="老师ID" width="200" align="center"/>

        <el-table-column prop="buyCount" label="购买数量" width="100" align="center"/>

          <el-table-column label="操作" width="500" align="center">
        <template slot-scope="scope">
          <router-link :to="'/course/info/'+scope.row.id">
          <el-button type="primary" size="mini" icon="el-icon-edit" @click="updateInfoById(scope.row.id)">修改课程基本信息</el-button>
          </router-link>
          <router-link :to="'/course/chapter/'+scope.row.id">
          <el-button type="primary" size="mini" icon="el-icon-edit" @click="updateDataById(scope.row.id)">修改课程大纲</el-button>
          </router-link>
          <el-button type="danger" size="mini" icon="el-icon-delete" @click="removeDataById(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->

    <el-pagination
      @size-change="getCoursedata"
      @current-change="getCoursedata"
      :current-page="current"
      :page-sizes="[3, 4, 5]"
      :page-size= size
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
  </div>
</template>

<script>
import course from '@/api/edu/course'
import chapter from '@/api/edu/chapter'

export default {
  data(){
    return{
      CourseListInfo:{},
      list: null,
      current:0,
      size:0,
      total:0
    }
  },
  created() {
    this.getCoursedata()
  },
  methods:{
    getCoursedata(current=1,size=3){
      this.current = current
      this.size = size
      course.getCoursedata(this.current,this.size,this.CourseListInfo)
      .then(response=>{
         this.list = response.data.list
        this.total = response.data.total
        }
      )
    },
    resetData(){
      this.CourseListInfo ={}
    },
    removeDataById(id){
      course.delCoursedata(id)
      .then(response=>{
        this.$message({
          type: 'success',
          message: '成功删除成功'
          }
        );
        this.getCoursedata()
      })
    },
    updateInfoById(id){
      this.$router.push({path:'/course/info/'+id})
    },
    updateDataById(id){
      this.$router.push({path:'/course/chapter/'+id})
    }

  }
}
</script>

<style scoped>

</style>
